<%@ page import="cqcvc.edu.cn.dao.HouseDao" %>
<%@ page import="cqcvc.edu.cn.entity.HouseInfo" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: zhouyz
  Date: 2023/1/4
  Time: 11:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<jsp:include page="../index/index-header.jsp"></jsp:include>
<script>
    function mOut(index) {
        switch(index){
            case 0:
                $('#house_detail').text('房间详情');
                $('#house_pic').attr('src','images/houseShowPic?id=9');
                break;
            case 1:
                break;
        }
    }
</script>

<body>
<%
    HouseDao houseDao=new HouseDao();
    List<HouseInfo> houseInfos=(List<HouseInfo>)application.getAttribute("houseInfos");

    out.println("<script>");
    out.println("function mOut(index) {");
    out.println( " switch(index) {");
    for(int i=0;i<4 && i<houseInfos.size();i++)
    {
        out.println(" case "+i+":");
        out.println("$('#house_detail').text('"+houseInfos.get(i).getHouseDetail()+"');");
        out.println(" $('#house_pic').attr('src','images/houseShowPic?id="+houseInfos.get(i).getId()+"');");
        out.println(" break;");
    }
    out.println("}}");
    out.println("</script>");
%>
<div class="container">
    <div class="room" ng-controller="roomCtrl" ng-init="getList()">
        <img src="images/slider2.png" style="margin-bottom: 10px" />
        <div class="row">
            <div class="content col-lg-5">
                <div class="col-xs-8">
                    <div ng-if="active">
                        <img id="house_pic" src="images/houseShowPic?id=9" alt="" class="img-thumbnail"
                             height="209px"/>
                        <p id="house_detail" ng-bind="active.houseTitle">
                            房间内以典型中国风式的装潢，配合极具韵味的古式家具。庄严气派却不失温馨。与室内装潢不同的是，其现代设施也是应有尽有；月子期间对温度十分敏感，室内的中央空调能够带来舒适的温度，屋内设有独立卫生间，影音设备应有尽有，让您在娱乐中度过在月子中心的每一天。</p>
                    </div>
                </div>
                <div class="col-xs-4">

                    <%
                        for(int i=0;i<4 && i<houseInfos.size();i++) {
                    %>
                    <ul class="list-group" style="margin-bottom:6px">
                        <li class="list-group-item" ng-repeat="item in data | limitTo:4" ng-class="{\'list-group-item-info\':isActive(item)}">
                            <a onclick="mOut(<%=i%>)"><img src="images/houseShowPic?id=<%=houseInfos.get(i).getId()%>" alt="" class="img-responsive" style="height: 80px" /></a>
                        </li>
                    </ul>
                    <%
                        }
                    %>

                </div>
            </div>

            <div class="content col-lg-7">
                <%
                    String pageCurrent=request.getParameter("pageCurrent");
                    int startPage=((pageCurrent!=null) && !"".equals(pageCurrent)) ? Integer.parseInt(pageCurrent) :1 ;
                    for(int i=(startPage-1)*10;i<10*startPage && i<houseInfos.size();i++) {
                %>
                <ul class="list-group" style="margin-bottom:1px">
                    <li class="list-group-item">
                        <a href="house_detail?id=<%=houseInfos.get(i).getId()%>" class="row">
                            <span class="pull-left targe">[房间介绍] <%=houseInfos.get(i).getHouseTitle()%></span>
                            <span class="pull-right date"><%=houseInfos.get(i).getCreateDate()%> &nbsp;&nbsp;</span>
                        </a>
                    </li>
                </ul>
                <%
                    }
                %>

            </div>
        </div>

        <div class="btn-group col-xs-offset-5">
            <ul class="pagination">
                <li><a onclick="page(-1)">&laquo;</a></li>
                <%
                    //总页数：总条数是否是每页数的整数倍，如果是则：总页数/每页数，否则：总页数/每页数+1
                    int pageCount = ((houseInfos.size() % 10) > 0) ? (houseInfos.size() / 10 + 1) : houseInfos.size() / 10;
                    for(int i=1;i<=pageCount;i++){
                %>

                <li><a href="house.jsp?pageCurrent=<%=i%>"><%=i%></a></li>
                <%
                    }
                %>

                <li><a onclick="page(1)">&raquo;</a></li>
            </ul>
            <script>
                function page(param) {
                    if(param==-1)//前一页
                    {
                        var currentPage=<%=startPage%>;
                        if(currentPage>1)
                        {
                            this.window.location.href="house.jsp?pageCurrent="+(currentPage-1);
                        }
                    }
                    else if(param==1)//后一页
                    {
                        var currentPage=<%=startPage%>;
                        if(currentPage<<%=pageCount%>)
                        {
                            this.window.location.href="house.jsp?pageCurrent="+(currentPage+1);
                        }
                    }
                }
            </script>
        </div>
    </div>
</div>
<jsp:include page="../index/index-foot.jsp"></jsp:include>
</body>
</html>
